#define _CRT_SECURE_NO_WARNINGS 1	
//#include<stdio.h>
//#include <stdlib.h>
//#include <math.h>
//#include <string.h>
//struct person
//{
//	char name[20];
//	char sfz[19];
//	int age;
//}student;
//FILE* fp1, * fp2;
//void save()
//{
//	int i;
//	fp1 = fopen("./src/stud.dat", "wb");
//	for (i = 0; i < 5; i++)
//	{
//		scanf("%s%s%d", student.name, student.sfz, &student.age);
//		fwrite(&student, sizeof(student), 1, fp1);
//	}
//	fclose(fp1);
//}
//int main()
//{
//	void save();
//	int q = 0, i;
//	fp1 = fopen("./src/stud.dat", "rb");
//	fp2 = fopen("./src/result.dat", "wb");
//	char quan2[18] = { 0 };
//	int quan[17] = { 7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2 };
//	char check[11] = { '1','0','X','9','8','7','6','5','4','3','2' };
//	while ((fread(&student, sizeof(student), 1, fp1)) == 1)
//	{
//		int sign = 0;
//		int j = 0, sum = 0;
//		for (i = 0; i < 18; i++)
//		{
//			quan2[j++] = student.sfz[i];
//		}
//		for (i = 0; i < 17; i++)
//		{
//			sum += (quan[i] * (quan2[i] - '0'));
//		}
//		int k = sum % 11;
//		if (check[k] != quan2[17])
//		{
//			if (q == 0)
//				fprintf(fp2, "%s", student.name);
//			if (q != 0)
//				fprintf(fp2, ",%s", student.name);
//			q++;
//		}
//	}
//	fclose(fp1);
//	fclose(fp2);
//	return 0;
//}
#include <stdio.h>
#include <stdlib.h>
struct student
{
	char name[20];
	int score[4];
};
typedef struct student student;
void count()
{
	student st;
	FILE* fp1, * fp2;
	int i = 0;
	float sum1 = 0, sum2 = 0, sum3 = 0, sum4 = 0, sum5 = 0;
	fp1 = fopen("./src/zy.dat", "rb");
	if (!fp1)
	{
		printf("cann't create file\n");
		exit(0);
	}
	fp2 = fopen("./src/result.dat", "wb");
	if (!fp2)
	{
		printf("cann't create file\n");
		exit(0);
	}
	while (fread(&st, sizeof(student), 1, fp1) == 1)
	{
		sum1 += st.score[0];
		sum2 += st.score[1];
		sum3 += st.score[2];
		sum4 += st.score[3];
		i++;
	}
	sum1 /= (i * 25);
	sum2 /= (i * 25);
	sum3 /= (i * 25);
	sum4 /= (i * 25);
	fprintf(fp2, "%f %f %f %f ", sum1, sum2, sum3, sum4);
	fclose(fp1);
	fclose(fp2);
}
int main()
{
	count();
	return 0;
}
#include <stdio.h>
#include <stdlib.h>
struct books
{
	char sm[30];
	int gmrq;
	int price;
};
void save()
{
	FILE* fp1, * fp2;
	int i = 0;
	struct books st;
	if ((fp1 = fopen("./src/book.dat", "rb")) == NULL)
	{
		printf("cannot open file\n");
		exit(0);
	}
	if ((fp2 = fopen("./src/cheapbk.dat", "wb")) == NULL)
	{
		printf("cannot open file\n");
		exit(0);
	}
	float av = 0;
	while (fread(&st, sizeof(struct books), 1, fp1) == 1)
	{
		av += st.price * 1.0;
		i++;
	}
	av /= i;
	rewind(fp1);
	i = 0;
	while (fread(&st, sizeof(struct books), 1, fp1) == 1)
	{
		if (st.price < av)
		{
			fwrite(&st, sizeof(struct books), 1, fp2);
		}
	}
	fclose(fp1);
	fclose(fp2);
}
int main()
{
	save();
	return 0;
}
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct person
{
	char name[20];
	int score[5];
};
int main()
{
	struct person st[100];
	int i = 0, j, sum, su[100];
	char s[20];
	FILE* fp1;
	if ((fp1 = fopen("./src/pf.dat", "rb")) == NULL)
	{
		printf("can't open this file");
	}
	while (fread(&st[i], sizeof(struct person), 1, fp1) == 1)
	{

		su[i] = st[i].score[0] + st[i].score[1] + st[i].score[2] + st[i].score[3] + st[i].score[4];
		//	printf("%s %d %d %d %d %d %d\n",st[i].name,st[i].score[0],st[i].score[1],st[i].score[2],st[i].score[3],st[i].score[4],su[i]);
		i++;

	}
	sum = su[0];
	strcpy(s, st[0].name);
	//	printf("%s\n",s);
	for (j = 0; j < i; j++)
	{
		if (su[j] > sum)
		{
			sum = su[j];
			strcpy(s, st[j].name);
		}
	}
	printf("%s is champion!", s);
	return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct student { char name[20]; int score; };
int main()
{
	FILE* fp;
	struct student st[100];
	int i, j, one, two, three;
	if ((fp = fopen("./src/qmscore.dat", "rb")) == NULL)
	{
		printf("can not open qmscore.dat\n");
		exit(0);
	}
	i = 0;
	while ((fread(&st[i], sizeof(struct student), 1, fp)) != NULL)
	{
		i++;
	}
	one = two = three = 0;
	for (j = 0; j < i; j++)
	{
		if (st[one].score < st[j].score)
			one = j;
	}
	for (j = 0; j < i; j++)
	{
		if (st[two].score < st[j].score && st[j].score < st[one].score)
			two = j;
	}
	for (j = 0; j < i; j++)
	{
		if (st[three].score < st[j].score && st[j].score < st[one].score && st[j].score < st[two].score)
			three = j;
	}
	fclose(fp);
	printf("%s:%s:%s\n", st[one].name, st[two].name, st[three].name);
}
